1743B - Permutation Value - CodeForces Solution


greedy

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n=int(input())
    
    ans=[1]
    
    for j in range(3,n+1):
        ans.append(j)
        
    ans.append(2)
    
    for i in range(n):
        if(i<n-1):
            print(ans[i],end=' ')
        else:
            print(ans[i])

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll t;
    cin>>t;
    while(t--){
      ll n;
      cin>>n;
      ll a[n];
      ll i=0;
      ll j=1;
      while(i<n/2){
          a[i]=j;
          j++;
          a[n-1-i]=j;
          j++;
          i++;
      }
      if(n%2==1){
          a[n/2]=n;
      }
      for(ll k=0;k<n;k++){
          cout<<a[k]<<" ";
      }
      cout<<endl;
    }
	return 0;
}


Comments

Submit
0 Comments
More Questions

189A - Cut Ribbon
1182A - Filling Shapes
82A - Double Cola
45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci